package com.haha.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class save extends AppCompatActivity {
    private static final  String TAG="Save";
    EditText dollarText;
    EditText euroText;
    EditText wonText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.week4save);
        Intent intent=getIntent();
        //取数据的时候要注意数据类型
        float dollar2=intent.getFloatExtra("dollar_rate_key",0.0f);//key不存在时，将默认值0。0f付给dollar2
        float euro2=intent.getFloatExtra("euro_rate_key",0.0f);
        float won2=intent.getFloatExtra("won_rate_key",0.0f);

        Log.i(TAG,"onCreate:dollar2="+dollar2);
        Log.i(TAG,"onCreate:euro2="+euro2);
        Log.i(TAG,"onCreate:won2="+won2);

        dollarText=(EditText)findViewById(R.id.dollar_rate);
        euroText=(EditText)findViewById(R.id.euro_rate);
        wonText=(EditText)findViewById(R.id.won_rate);

        dollarText.setText(String.valueOf(dollar2));
        euroText.setText((String.valueOf(euro2)));
        wonText.setText(String.valueOf(won2));
    }

    //指定一个保存数据的方法
    public void save(View btn){
        Log.i(TAG,"save:");
        //get new
        float newDollar=Float.parseFloat(dollarText.getText().toString());
        float newEuro=Float.parseFloat(euroText.getText().toString());
        float newWon=Float.parseFloat(wonText.getText().toString());
        Log.i(TAG,"获取到新的值");
        Log.i(TAG,"onCreate:newDollar="+newDollar);
        Log.i(TAG,"onCreate:newEuro="+newEuro);
        Log.i(TAG,"onCreate:newWon="+newWon);
        //save
        Intent intent =getIntent();
        Bundle bdl=new Bundle();
        bdl.putFloat("key_dollar",newDollar);
        bdl.putFloat("key_euro",newEuro);
        bdl.putFloat("key_won",newWon);
        intent.putExtras(bdl);
        setResult(2,intent);
        finish();
        //return
    }

}
